package org.marsdonne.commons;

import graphql.relay.DefaultConnectionCursor;
import graphql.relay.DefaultEdge;
import graphql.relay.Edge;

import java.util.List;
import java.util.stream.Collectors;

public interface GraphQLVersionedPageable<T extends VersionedIdentifiable> extends GraphQLPageable<T> {
    @Override
    default List<Edge<T>> getEdges(List<T> records, int first) {
        return (List) records.stream().limit(first).map((node) ->
                new DefaultEdge(node, new DefaultConnectionCursor(String.valueOf(node.getLastUpdated().getTime())))
        ).collect(Collectors.toList());
    }
}
